package com.cmc6.user.controller;

import com.cmc6.common.util.ApiResult;
import com.cmc6.user.model.dto.EmailNotBlankDTO;
import com.cmc6.user.model.dto.RegByEmailDTO;
import com.cmc6.user.service.RegByEmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "用户注册-通过邮箱")
@RequestMapping("/reg/email")
@RestController
public class RegByEmailController {

    @Resource
    RegByEmailService baseService;

    @PostMapping
    @ApiOperation(value = "注册")
    public ApiResult<String> regByEmail(@RequestBody @Valid RegByEmailDTO dto) {
        return ApiResult.ok(baseService.regByEmail(dto));
    }

    @PostMapping("/sendCode")
    @ApiOperation(value = "发送验证码")
    public ApiResult<String> sendCode(@RequestBody @Valid EmailNotBlankDTO dto) {
        return ApiResult.ok(baseService.sendCode(dto, 1));
    }

}
